<form action="index.php/contacter/update/" method="post" name="myform" id="myform">
<div id="inline1">
<h2><span>联系人信息</span></h2>
<table>
    <tr><th colspan="5">联系人：</th></tr>
    <tr>
        <td class="name" width="80"><span>*</span>对应客户：</td>
        <td width="170" colspan="4" >
        	<input id="customer_name" class="text_width" autocomplete="off" style=" width:427px;" type="text" name="customer_name" value=<?=$update_contacter->customer_name?>></input>
        </td>
    </tr>
    <tr>
        <td class="name" width="80"><span>*</span>姓名：</td>
        <td width="170"><input type="text" name="name"  value=<?=$update_contacter->name?> ></input></td>
        <td>&nbsp;</td>
        <td class="name" width="80">性别：</td>
        <?php
            $gender = '女';
            if ($update_contacter->sex) {
                $gender = '男';
            }
            ?>
        <td width="170" class="ie_6">
            <input type="radio" name="sex" id="man" <?php if($gender == '男'):?> checked="checked" <?php endif;?> value="1"/>
            <label for="man">男</label>
            <input type="radio" id="woman" name="sex" <?php if($gender == '女'):?> checked="checked" <?php endif;?> value="0"/>
            <label for="woman">女</label>
        </td>
    </tr>
    <tr>
        <td class="name" width="80">负责业务：</td>
        <td width="170"><input type="text" name="business" value=<?=$update_contacter->business?> ></input></td>
        <td>&nbsp;</td>
        <!-- <td class="name" width="80">分类：</td>
        <td width="170">
            <select name="classify">
            	<option value="3" >普通</option>
            	<option value="2" >不重要</option>
            	<option value="4" >重要</option>
                <option value="5" >特别重要</option>
                <option value="1" >失效</option>
            </select>
        </td> -->
    </tr>
    <tr><th>现任单位：</th><th colspan="4" valign="middle" style="text-align:right;"><a title="单位变更" class="unit_ch" style="cursor:pointer; color:#333; font-weight:normal;" id="add_company">单位变更 <img src="images/pl-add.png" align="TextTop" /></a>&nbsp;&nbsp;</th></tr>
    <tr>
        <td class="name" width="80"><span>*</span>称谓：</td>
        <td width="170"><input class="gj_text" type="text" id="appellation" name="appellation" value=<?=$update_contacter->appellation?> ></input></td>
        <td>&nbsp;</td>
        <td class="name" width="80">类型：</td>
        <td width="170"><input class="gj_text" type="text" id="type" name="type" value=<?=$update_contacter->type?>></input></td>
    </tr>
    <tr>
        <td class="name" width="80"><span>*</span>部门：</td>
        <td width="170"><input class="gj_text" type="text" id="department" name="department" value=<?=$update_contacter->department?> ></input></td>
        <td>&nbsp;</td>
        <td class="name" width="80"><span>*</span>职务：</td>
        <td width="170"><input class="gj_text" type="text" id="post" name="post" value=<?=$update_contacter->post?> ></input></td>
    </tr>
    <tr class="old_job"><th>历任单位：</th><th colspan="4" valign="middle" style="text-align:right;"><a style="cursor:pointer;" title="删除历任单位"><span><img id="unit_delete" src="images/pl-del.png" /></span></a>&nbsp;&nbsp;</th></tr>
    <tr class="old_job">  <!-- 隐藏的历任单位 -->
        <td class="name" width="80">称谓：</td>
        <td width="170"> <span id="span1"></span></td>
        <td>&nbsp;</td>
        <td class="name" width="80">类型：</td>
        <td width="170"><span id="span2"></span></td>
    </tr>
    <tr class="old_job">
        <td class="name" width="80">部门：</td>
        <td width="170"> <span id="span3"></span></td>
        <td>&nbsp;</td>
        <td class="name" width="80">职务：</td>
        <td width="170"> <span id="span4"></span></td>
    </tr>

    <script language="JavaScript" type="text/javascript">
			$(document).ready(function(){
				$("#unit_delete").click(function(){
				if (window.confirm("您确定要删除吗？")) {
					var old_units_id = $("#old_units_id").val();
					$.post("index.php/contacter/delete_old_units", { id: old_units_id },
   							function(data){
     						if(data == 1){
								alert('删除成功');
								$(".old_job").html('');
     						}else{
     							alert('删除失败');
     						}
   					});
				}
			})
			});
    </script>

	<?php foreach($old_units as $old_unit):?>
    <tr class="old_units<?= $old_unit->id?>"><th>历任单位：</th><th colspan="4" valign="middle" style="text-align:right;"><a style="cursor:pointer;" title="删除历任单位"><span><img id="unit_delete<?= $old_unit->id?>" src="images/pl-del.png" /></span></a>&nbsp;&nbsp;</th></tr>
    <tr class="old_units<?= $old_unit->id?>">  <!-- 循环显示的历任单位 -->
        <td class="name" width="80">称谓：</td>
        <td width="170"> <?= $old_unit->appellation?></td>
        <td>&nbsp;</td>
        <td class="name" width="80">类型：</td>
        <td width="170"><?= $old_unit->type?></td>
    </tr>
    <tr class="old_units<?= $old_unit->id?>">
        <td class="name" width="80">部门：</td>
        <td width="170"> <?= $old_unit->department?></td>
        <td>&nbsp;</td>
        <td class="name" width="80">职务：</td>
        <td width="170"> <?= $old_unit->post?></td>
    </tr>

    <script language="JavaScript" type="text/javascript">
			$(document).ready(function(){
				$("#unit_delete<?= $old_unit->id?>").click(function(){
				if (window.confirm("您确定要删除吗？")) {
					$.post("index.php/contacter/delete_old_units", { id: <?= $old_unit->id?> },
   							function(data){
     						if(data == 1){
								alert('删除成功');
								$(".old_units<?= $old_unit->id?>").html('');
     						}else{
     							alert('删除失败');
     						}
   					});
				}
			})
			});
    </script>

	<?php endforeach;?>
    <script type="text/javascript">
    	$(document).ready(function(){
			$("#add_company").click(function(){
				var appellation=$("#appellation").val();
				var type=$("#type").val();
				var department=$("#department").val();
				var post=$("#post").val();
				var id=$("#id").val();
				var customer_name=$("#customer_name").val();
				if(appellation == '' || department == '' || post == ''){
					alert('请在填写数据后在提交为历任单位');
				}else{
					$.post("index.php/contacter/add_old_units", {id: id, appellation: appellation, type: type, department: department, post: post, old_unit: customer_name },
   					function(data){
     				if(data >=1 ){
     					alert("添加成功");
						$(".old_job").show();
						$("#old_units_id").val(data);
						$("#span1").append(appellation);
						$("#span2").append(type);
						$("#span3").append(department);
						$("#span4").append(post);

						$("#appellation").val('');
						$("#type").val('');
						$("#department").val('');
						$("#post").val('');
     				}else{
     					alert("添加失败");
     				}
   				});
				}
			});
		});
    </script>

    <tr><th colspan="5">联系：</th></tr>
    <tr>
        <td class="name" width="80">工作电话：</td>
        <td width="170"><input type="text" name="work_tel" value=<?=$update_contacter->work_tel?> ></input></td>
        <td>&nbsp;</td>
        <td class="name" width="80">传真：</td>
        <td width="170"><input type="text" name="fax" value=<?=$update_contacter->fax?> ></input></td>
    </tr>
    <tr>
        <td class="name" width="80">移动电话：</td>
        <td width="170"><input type="text" name="mobile_phone" value=<?=$update_contacter->mobile_phone?> ></input></td>
        <td>&nbsp;</td>
        <td class="name" width="80">家庭电话：</td>
        <td width="170"><input type="text" name="home_tel" value=<?=$update_contacter->home_tel?> ></input></td>
    </tr>
    <tr>
        <td class="name" width="80">邮件地址：</td>
        <td width="170"><input type="text" name="email" value=<?=$update_contacter->email?> ></input></td>
        <td>&nbsp;</td>
        <td class="name" width="80">QQ：</td>
        <td width="170"><input type="text" name="qq" value=<?=$update_contacter->qq?> ></input></td>
    </tr>
    <tr>
        <td class="name" width="80">邮编：</td>
        <td width="170"><input type="text" name="postcode" value=<?=$update_contacter->postcode?> ></input></td>
        <td>&nbsp;</td>
        <td class="name" width="80">家庭地址：</td>
        <td width="170"><input type="text" name="home_address" value=<?=$update_contacter->home_address?> ></input></td>
    </tr>
    <tr><th colspan="5">附加：</th></tr>
    <tr>
        <td class="name" width="80">兴趣：</td>
      	<td width="170" colspan="4">
        <input style=" width:427px;" name="interest" type="text" value=<?=$update_contacter->interest?>></input>
    </tr>
    <tr>
        <td class="name" width="80">爱好：</td>
      	<td width="170" colspan="4">
        <input style=" width:427px;" name="hobby" type="text" value=<?=$update_contacter->hobby?>></input>
    </tr>
    <tr>
        <td class="gj_name">备注：</td>
        <td colspan="5"><textarea name="remark"><?=$update_contacter->remark?></textarea></td>
    </tr>
    <tr><td colspan="5">&nbsp;</td></tr>
    <tr class="sub">
        <td colspan="5"><input type="button" class="opp_edit_tijiao" value="提交" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="重置" /></td>
    </tr>
</table>
</div>
<input class="text_width" type="hidden" name="hidden_name" value=<?=$update_contacter->customer_name?>></input>
<input type="hidden" name="id" id="id" value=<?=$update_contacter->id?> >
<input type="hidden" name="customerid" value=<?=$update_contacter->customer_id?> >
</form>
<input type="hidden" name="old_units_id" id="old_units_id" > <!-- 历任单位编号 -->
<!--共享弹出框-->
<script type="text/javascript">
	$(function(){
		$(".opp_edit_tijiao").click(function(){
			var error="";
			var customer_name = $(":input[name='customer_name']").val();
			var name=$(":input[name='name']").val();
			var appellation=$(":input[name='appellation']").val();
			var department=$(":input[name='department']").val();
			var post=$(":input[name='post']").val();

			if($.trim(customer_name) == ""){
				 error="错误：\x0d";
	             error+="对应客户不允许为空,请填写\x0d";
		    }
			
			if($.trim(name) == ''){
				if(error==""){
			    	 error="错误：\x0d";
				 }
	             error+="用户名称不允许为空,请填写\x0d";
		    }
			if($.trim(appellation) == ''){
		    	if(error==""){
			    	 error="错误：\x0d";
				 }
		         error+="请先填写称谓,在提交\x0d";
			}
		    if($.trim(department) == ''){
		    	if(error==""){
			    	 error="错误：\x0d";
				 }
		       	 error+="请先填写部门,在提交\x0d";
			}
		    if($.trim(post) == ''){
		    	if(error==""){
			    	 error="错误：\x0d";
				 }
		     	 error+="请先填写职务,在提交\x0d";
			}
	        if(error != ""){
	        	alert(error);
	        }else{
	           $("#myform").submit();
	        }
			
		})
	})
</script>
<script language="javascript">
	$(document).ready(function() {
		new PopupLayer({trigger:"#ele1",popupBlk:"#blk1",closeBtn:".close1",useOverlay:true});
	});
</script>